<template>
	<view class="container">
		<view class="coupon-list" v-if="list.length">
			<view class="coupon-item" v-for="(item, index) in list" :key="index">
				<!--  -->
				<view :class="'item-wrapper color__' + (item.state.value ? item.color.text : 'gray')">
					<view class="coupon-type">{{ item.coupon_type.text }}</view>
					<view class="tip dis-flex flex-dir-column flex-x-center">
						<view v-if="item.coupon_type.value == 10">
							<text class="f-30">￥</text>
							<text class="money">{{ item.reduce_price }}</text>
						</view>
						<text class="money" v-if="item.coupon_type.value == 20">{{ item.discount }}折</text>
						<text class="pay-line">满{{ item.min_price }}元可用</text>
					</view>
					<view class="split-line"></view>
					<view class="content dis-flex flex-dir-column flex-x-between">
						<view class="title">{{ item.name }}</view>
						<view class="bottom dis-flex flex-y-center">
							<view class="time flex-box">
								<text v-if="item.expire_type == 10">领取{{ item.expire_day }}天内有效</text>
								<text v-if="item.expire_type == 20">{{ item.start_time.text }}~{{ item.end_time.text }}</text>
							</view>
							<view class="receive" v-if="item.state.value" @tap="receive" :data-coupon-id="item.coupon_id"><text>立即领取</text></view>
							<view class="receive state" v-else>
								<text>{{ item.state.text }}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import Tools from '@/utils/Tools.js';
export default {
	data() {
		return {
			options: {},
			// 优惠券列表
			list: [],

			// show
			notcont: false
		};
	},
	onLoad(options) {
		// 当前页面参数
		this.options = options;
	},
	onShow() {
		// 获取优惠券列表
		this.getCouponList();
	},
	methods: {
		/**
		 * 获取优惠券列表
		 */
		getCouponList() {
			this.$get(this.$api.getCouponList, {}, res => {
				this.list = res.data.list;
				this.notcont = !res.data.list.length;
			});
		},
		/**
		 * 立即领取
		 */
		receive(e) {
			let couponId = e.currentTarget.dataset.couponId;
			this.$post(this.$api.receiveUserCoupon, { coupon_id: couponId }, res => {
				Tools.showSuccess(res.msg);
				this.getCouponList();
			});
			// App._post_form(
			// 	'user.coupon/receive',
			// 	{
			// 		coupon_id: couponId
			// 	},
			// 	function(result) {
			// 		App.showSuccess(result.msg);
			// 		// 获取优惠券列表
			// 		_this.getCouponList();
			// 	}
			// );
		}
	}
};
</script>

<style>
page,
.container {
	background: #fff;
}

.coupon-list {
	padding: 20rpx;
}

.coupon-list .coupon-item {
	position: relative;
	overflow: hidden;
	margin-bottom: 22rpx;
}

.coupon-list .coupon-item .item-wrapper {
	width: 100%;
	display: flex;
	background: #fff;
	border-radius: 8rpx;
	color: #fff;
	height: 180rpx;
}

.coupon-list .coupon-item .item-wrapper .coupon-type {
	position: absolute;
	top: 0;
	right: 0;
	z-index: 10;
	width: 128rpx;
	padding: 3px 0;
	background: #a771ff;
	font-size: 20rpx;
	text-align: center;
	color: #fff;
	transform: rotate(45deg);
	transform-origin: 64rpx 64rpx;
}

.coupon-list .coupon-item .item-wrapper.color__blue {
	background: linear-gradient(-125deg, #57bdbf, #2f9de2);
}

.coupon-list .coupon-item .item-wrapper.color__red {
	background: linear-gradient(-128deg, #ff6d6d, #ff3636);
}

.coupon-list .coupon-item .item-wrapper.color__violet {
	background: linear-gradient(-113deg, #ef86ff, #b66ff5);
}

.coupon-list .coupon-item .item-wrapper.color__violet .coupon-type {
	background: #55b5ff;
}

.coupon-list .coupon-item .item-wrapper.color__yellow {
	background: linear-gradient(-141deg, #f7d059, #fdb054);
}

.coupon-list .coupon-item .item-wrapper.color__gray {
	background: linear-gradient(-113deg, #bdbdbd, #a2a1a2);
}

.coupon-list .coupon-item .item-wrapper.color__gray .coupon-type {
	background: #9e9e9e;
}

.coupon-list .coupon-item .item-wrapper .content {
	flex: 1;
	padding: 30rpx 20rpx;
	border-radius: 8px 0 0 8px;
}

.coupon-list .coupon-item .item-wrapper .content .title {
	font-size: 38rpx;
}

.coupon-list .coupon-item .item-wrapper .content .bottom .time {
	font-size: 24rpx;
}

.coupon-list .coupon-item .item-wrapper .content .bottom .receive {
	height: 46rpx;
	width: 122rpx;
	line-height: 46rpx;
	text-align: center;
	border: 1px solid #fff;
	border-radius: 30rpx;
	color: #fff;
	font-size: 24rpx;
}

.coupon-list .coupon-item .item-wrapper .content .bottom .receive.state {
	border: none;
}

.coupon-list .coupon-item .item-wrapper .tip {
	position: relative;
	flex: 0 0 32%;
	text-align: center;
	border-radius: 0 8px 8px 0;
}

.coupon-list .coupon-item .item-wrapper .tip .money {
	font-weight: bold;
	font-size: 52rpx;
}

.coupon-list .coupon-item .item-wrapper .tip .pay-line {
	font-size: 22rpx;
}

.coupon-list .coupon-item .item-wrapper .split-line {
	position: relative;
	flex: 0 0 0;
	border-left: 4rpx solid #fff;
	margin: 0 5px 0 3px;
	background: #fff;
}

.coupon-list .coupon-item .item-wrapper .split-line:before,
.coupon-list .coupon-item .item-wrapper .split-line:after {
	content: '';
	position: absolute;
	width: 12px;
	height: 6px;
	background: #f7f7f7;
	left: -7px;
	z-index: 1;
}

.coupon-list .coupon-item .item-wrapper .split-line:before {
	border-radius: 0 0 8px 8px;
	top: 0;
}

.coupon-list .coupon-item .item-wrapper .split-line:after {
	border-radius: 8px 8px 0 0;
	bottom: 0;
}
</style>
